Component({
    properties: {
        type: {
            type: Number,
            value: 1
        },
        preActive: {
            type: Number,
            value: -1
        }
    },
    data: {
        active: 0,
        list: [
            {
                "pagePath": "/pages/home/index/index",
                "iconPath": "/assets/images/icon/index.png",
                "selectedIconPath": "/assets/images/icon/index_select.png",
                "text": "首页"
            },
            {
                "pagePath": "/pages/strategy/index/index",
                "iconPath": "/assets/images/icon/strategy.png",
                "selectedIconPath": "/assets/images/icon/strategy_select.png",
                "text": "攻略"
            },
            {
                "pagePath": "/pages/dynamic/index/index",
                "iconPath": "/assets/images/icon/dynamic.png",
                "selectedIconPath": "/assets/images/icon/dynamic_select.png",
                "text": "旅游圈"
            },
            {
                "pagePath": "/pages/message/index/index",
                "iconPath": "/assets/images/icon/message.png",
                "selectedIconPath": "/assets/images/icon/message_select.png",
                "text": "消息",
                "showMessage": true
            },
            {
                "pagePath": "/pages/mine/index/index",
                "iconPath": "/assets/images/icon/mine.png",
                "selectedIconPath": "/assets/images/icon/mine_select.png",
                "text": "我的"
            }
        ],
        peopleList: [
            {
                "pagePath": "/pages/home/index/index",
                "iconPath": "/assets/images/icon/index.png",
                "selectedIconPath": "/assets/images/icon/index_select.png",
                "text": "首页"
            },
            {
                "pagePath": "/pages/strategy/index/index",
                "iconPath": "/assets/images/icon/strategy.png",
                "selectedIconPath": "/assets/images/icon/strategy_select.png",
                "text": "攻略"
            },
            {
                "pagePath": "/pages/dynamic/index/index",
                "iconPath": "/assets/images/icon/dynamic.png",
                "selectedIconPath": "/assets/images/icon/dynamic_select.png",
                "text": "旅游圈"
            },
            {
                "pagePath": "/pages/message/index/index",
                "iconPath": "/assets/images/icon/message.png",
                "selectedIconPath": "/assets/images/icon/message_select.png",
                "text": "消息",
                "showMessage": true
            },
            {
                "pagePath": "/pages/mine/index/index",
                "iconPath": "/assets/images/icon/mine.png",
                "selectedIconPath": "/assets/images/icon/mine_select.png",
                "text": "我的"
            }
        ],
        landlordList: [
            {
                "pagePath": "/pages/house/list/list",
                "iconPath": "/assets/images/icon/house.png",
                "selectedIconPath": "/assets/images/icon/house_select.png",
                "text": "房源"
            },
            {
                "pagePath": "/pages/landlord/order/list/list",
                "iconPath": "/assets/images/icon/order.png",
                "selectedIconPath": "/assets/images/icon/order_select.png",
                "text": "订单"
            },
            {
                "pagePath": "/pages/landlord/dynamic/index/index",
                "iconPath": "/assets/images/icon/news.png",
                "selectedIconPath": "/assets/images/icon/news_select.png",
                "text": "推荐"
            },
            {
                "pagePath": "/pages/statistics/list/list",
                "iconPath": "/assets/images/icon/mine.png",
                "selectedIconPath": "/assets/images/icon/mine_select.png",
                "text": "我的"
            }
        ]
    },
    lifetimes: {
        ready() {
            const data = this.data.type === 1 ? this.data.peopleList : this.data.landlordList
            this.setData({
                list: data,
            })
            if (this.data.preActive > -1) {
                this.setData({
                    active: this.data.preActive
                })
            }
        }
    },
    methods: {
        onChange(event) {
            this.setData({ active: event.detail });
            this.data.type === 1 ? wx.switchTab({
                url: this.data.list[event.detail].pagePath
            }) : wx.redirectTo({
                url: this.data.list[event.detail].pagePath
            });
            wx.vibrateShort({
                type: 'medium'
            })
        },

        init() {
            // 获取信息数量
            const app = getApp()
            this.setData({
                message: app.messageNumber || 0
            })

            const page = getCurrentPages().pop();
            this.setData({
                active: this.data.list.findIndex(item => item.pagePath === `/${page.route}`)
            });
        },

        changeMenu(type) {
            const data = type === 1 ? this.data.peopleList : this.data.landlordList
            type === 1 ? wx.switchTab({
                url: data[0].pagePath
            }) : wx.redirectTo({
                url: data[0].pagePath
            });
        }
    }
});
